import 'package:flutter/material.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';

///用户头像（包括VIP）
class HeaderWidget extends StatelessWidget {
  final String headPath;

  final double headWidth;

  final double headHeight;

  //vip显示的高度
  final double? borderHeight;

  final Widget? defaultHead;

  final int level;
  final bool isCircle;
  final double? radius;

  final VoidCallback? tabCallback; //点击头像

  const HeaderWidget({
    Key? key,
    required this.headPath,
    required this.level,
    required this.headWidth,
    required this.headHeight,
    this.borderHeight,
    this.defaultHead,
    this.tabCallback,
    this.isCircle = true,
    this.radius,
  });

  @override
  Widget build(BuildContext context) {
    Color _borderColor = _configVIPInfo();
    return GestureDetector(
      onTap: tabCallback,
      child: Container(
        width: headWidth,
        height: headHeight,
        decoration: isCircle
            ? BoxDecoration(
                border: Border.all(width: borderHeight ?? 4, color: _borderColor),
                shape: BoxShape.circle,
              )
            : null,
        child: ClipRRect(
          borderRadius: BorderRadius.circular(isCircle ? headWidth : radius ?? 0),
          child: NetworkImageLoader(
            imageUrl: headPath,
            width: headWidth,
            height: headHeight,
            fit: BoxFit.fitWidth,
          ),
        ),
      ),
    );
  }

  ///获取对应VIP的边框颜色和图片
  Color _configVIPInfo() {
    return const Color.fromRGBO(253, 45, 85, 1);
  }
}
